package fr.afcepf.atod18.service;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import fr.afcepf.atod18.dao.CustomerDAO;
import fr.afcepf.atod18.entity.Customer;

@Path("/customers")
public class CustomerServiceImpl implements CustomerService{
    
    private CustomerDAO  customerDAO;

    public void setCustomerDAO(CustomerDAO customerDAO) {
        this.customerDAO = customerDAO;
    }

    @Path("/nom/{name}")
    @GET
    @Produces ("application/xml")
    public Customer findUserByName(@PathParam("name") String name) {
        
        return customerDAO.findUserByName(name);
    }

    @Path("/save")
    @POST
    public void save(Customer entity) {
        customerDAO.save(entity);
    }

    @Path("/del")
    @POST
    public void delete(Customer entity) {
        customerDAO.delete(entity);
        
    }

    @Path("/upd")
    @POST
    @Produces ("application/xml")
    public Customer update(Customer entity) {
        return customerDAO.update(entity);
    }

    @Path("/{id}")
    @GET
    @Produces ("application/xml")
    public Customer find(@PathParam("id") int id) {
        return customerDAO.find(id);
    }

    @Path("/all")
    @GET
    @Produces ("application/xml")
    public List<Customer> findAll() {
        return customerDAO.findAll();
    }
}